#include "csutils.h"
#include <wx/window.h>
#include <wx/string.h>
#include "version.h"

Utils::Utils() {
   
}

Utils::~Utils() {
   
}

wxWindow* Utils::FindWindowRecursively(const wxWindow* parent, const wxString& partialLabel) {
    if ( parent )
    {
        #if defined(LOGGING)
           
        #endif
       
        if ( parent->GetLabel().Matches(partialLabel) )
            return (wxWindow *)parent;
        if ( parent->GetName().Matches(partialLabel) )
            return (wxWindow *)parent;

       
        for ( wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst();
              node; node = node->GetNext() )
        {
           
            wxWindow *win = (wxWindow *)node->GetData();
            wxWindow *retwin = FindWindowRecursively(win, partialLabel);
            if (retwin)
                return retwin;
        }
    }

   
    return NULL;
}

wxWindow* Utils::FindWindowRecursively(const wxWindow* parent, const wxWindow* handle) {
    if ( parent )
    {
       
        if ( parent == handle )
            return (wxWindow *)parent;

       
        for ( wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst();
              node;
              node = node->GetNext() )
        {
           
            wxWindow *win = (wxWindow *)node->GetData();
            wxWindow *retwin = FindWindowRecursively(win, handle);
            if (retwin)
                return retwin;
        }
    }

   
    return NULL;
}

wxWindow* Utils::WinExists(wxWindow *parent) {

    if ( !parent )
    {
        return NULL;
    }

   
    for ( wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
          node;
          node = node->GetNext() )
    {
       
        wxWindow* win = node->GetData();
        wxWindow* retwin = FindWindowRecursively(win, parent);
        if (retwin)
            return retwin;
    }

    return NULL;
}
